package com.ecoolex.chinadutyfree.retailer.core.manager;

import com.ecoolex.chinadutyfree.retailer.core.dao.DirectMailGoodsOrderCouponDAO;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderCoupon;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderCouponExample;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderCouponExample.Criteria;
import com.ecoolex.framework.common.util.Check;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DirectMailGoodsOrderCouponManager {

    @Autowired
    private DirectMailGoodsOrderCouponDAO dao;

    public List<DirectMailGoodsOrderCoupon> queryByOrderIdAndType(Integer orderId,Integer couponType){
    	DirectMailGoodsOrderCouponExample example = new DirectMailGoodsOrderCouponExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderId)
    	.andCouponTypeEqualTo(couponType)
    	.andDeletedEqualTo(DirectMailGoodsOrderCoupon.NOT_DELETED);
    	return dao.selectByExample(example);
    }
    
    public List<DirectMailGoodsOrderCoupon> queryByOrderId(Integer orderId){
    	DirectMailGoodsOrderCouponExample example = new DirectMailGoodsOrderCouponExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderId)
    	.andDeletedEqualTo(DirectMailGoodsOrderCoupon.NOT_DELETED);
    	return dao.selectByExample(example);
    }

    /**
     * 保存优惠券
     * @param coupon
     * @return
     */
    public DirectMailGoodsOrderCoupon save(DirectMailGoodsOrderCoupon coupon){
        Integer change = dao.insert(coupon);
        Check.notNull(change);
        Check.isEqual(change,1);
        return coupon;
    }
}